﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinaer.Model.Common;
using Chinaer.Core.Helper;

namespace Chinaer.Bll
{
    public class ShangJiaCaoZuo : Repository, IBll.IShangJiaCaoZuo
    {
        private static ShangJiaCaoZuo _instance = null;
        public static ShangJiaCaoZuo Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new ShangJiaCaoZuo();
                }
                return _instance;
            }
            set
            {
                _instance = value;
            }
        }
        private Chinaer.IDao.IShangJia_CaoZuoDAO shangJiaCaoZuoDAO = new Chinaer.Dao.ShangJiaCaoZuoDAO();
        public JsonResult Add(DTO.ShangJia_CaoZuoDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_ShangJia_CaoZuo model_ShangJiaCaoZuo = new Model.Entities.Model_ShangJia_CaoZuo();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_ShangJiaCaoZuo);
            if (string.IsNullOrEmpty(model_ShangJiaCaoZuo.ID) || model_ShangJiaCaoZuo.ID.Trim() == "")
            {
                model_ShangJiaCaoZuo.ID = Chinaer.Core.Helper.GenerateIDHelper.GenerateID();
            }
            jsonResult.Success = shangJiaCaoZuoDAO.Add(model_ShangJiaCaoZuo);
            return jsonResult;
        }

        public JsonResult Delete(DTO.ShangJia_CaoZuoDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_ShangJia_CaoZuo model_ShangJiaCaoZuo = new Model.Entities.Model_ShangJia_CaoZuo();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_ShangJiaCaoZuo);
            jsonResult.Success = shangJiaCaoZuoDAO.Delete(model_ShangJiaCaoZuo);
            return jsonResult;
        }

        public JsonResult Delete(string id)
        {
            JsonResult jsonResult = new JsonResult();
            jsonResult.Success = shangJiaCaoZuoDAO.Delete(id);
            return jsonResult;
        }

        public JsonResult Update(DTO.ShangJia_CaoZuoDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_ShangJia_CaoZuo model_ShangJiaCaoZuo = new Model.Entities.Model_ShangJia_CaoZuo();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_ShangJiaCaoZuo);
            jsonResult.Success = shangJiaCaoZuoDAO.Update(model_ShangJiaCaoZuo);
            return jsonResult;
        }

        public DTO.ShangJia_CaoZuoDTO GetByID(string id)
        {
            Model.Entities.Model_ShangJia_CaoZuo model_shangJiaCaoZuo = new Model.Entities.Model_ShangJia_CaoZuo();
            DTO.ShangJia_CaoZuoDTO shangJiaCaoZuoDTO = new DTO.ShangJia_CaoZuoDTO();
            model_shangJiaCaoZuo = shangJiaCaoZuoDAO.GetByID(id);
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(model_shangJiaCaoZuo, shangJiaCaoZuoDTO);
            return shangJiaCaoZuoDTO;
        }
    }
}
